package mil.af.amc.adpetracker.service;

import mil.af.amc.adpetracker.dao.EquipmentItemDao;
import mil.af.amc.adpetracker.dao.MaintenanceEntryDao;
import mil.af.amc.adpetracker.model.EquipmentItem;
import mil.af.amc.adpetracker.model.MaintenanceEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Please fill in this javadoc
 *
 * @author TSgt Jason Ferguson
 */
@Service("maintenanceService")
public class MaintenanceServiceImpl implements MaintenanceService {

    private MaintenanceEntryDao maintenanceEntryDao;

    @Autowired
    public void setMaintenanceEntryDao(MaintenanceEntryDao maintenanceEntryDao) {
        this.maintenanceEntryDao = maintenanceEntryDao;
    }

    private EquipmentItemDao equipmentItemDao;

    @Autowired
    public void setEquipmentItemDao(EquipmentItemDao equipmentItemDao) {
        this.equipmentItemDao = equipmentItemDao;
    }

    public List<MaintenanceEntry> getAll() {
        return null;
    }

    public List<MaintenanceEntry> getBySerialNumber(String serial) {

        return maintenanceEntryDao.getBySerialNumber(serial);
    }

    public MaintenanceEntry create(Map entryMap) {

        MaintenanceEntry entry = new MaintenanceEntry();

        entry.setEntryDate(new Date());
        entry.setEntryText((String) entryMap.get("entryText"));

        int itemId = (Integer) entryMap.get("itemId");
        EquipmentItem item = equipmentItemDao.getById(itemId);
        entry.setItem(item);

        MaintenanceEntry result = maintenanceEntryDao.save(entry);
        return result;
//        int maintId = maintenanceEntryDao.add(entry);
//        entry.setEntryId(maintId);
//
//        return entry;

    }


}
